package com.clz.hyperit.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.clz.hyperit.dao.FollowDao;
import com.clz.hyperit.entity.Collection;
import com.clz.hyperit.entity.Follow;
@Repository("followDao")
public class FollowDaoImpl extends BaseDaoImpl<Follow> implements FollowDao {

	public Follow getBy_articleId_userdetail_id(Integer blog_id,
			Integer userdetail_id) {
		String hql = " from Follow where blog_id = :blog_id and userdetail_id = :userdetail_id";
		return (Follow) getCurrentSession().createQuery(hql)
		.setInteger("blog_id", blog_id).setInteger("userdetail_id", userdetail_id).uniqueResult();
	}

	public void deleteBy_userdetail_id_target_id(Integer userdetail_id,
			Integer target_id) {
		String hql = " delete from Follow where blog_id = :blog_id and userdetail_id = :userdetail_id";
		 getCurrentSession().createQuery(hql)
		.setInteger("blog_id", target_id).setInteger("userdetail_id", userdetail_id).executeUpdate();
	}

	public Follow get_userid_targetid(Integer userdetail_id, Integer target_id) {
		String hql = " from Follow where blog_id = :blog_id and userdetail_id = :userdetail_id";
		 return (Follow) getCurrentSession().createQuery(hql)
			.setInteger("blog_id", target_id).setInteger("userdetail_id", userdetail_id).uniqueResult();
	}

	@SuppressWarnings("unchecked")
	public List<Follow> getByUserDetailId(Integer userdetail_id) {
		String hql = " from Follow where userdetail_id = :userdetail_id order by createtime desc";
		return	getCurrentSession().createQuery(hql)
		.setInteger("userdetail_id", userdetail_id).list();
	
	}
}
